package topcoder;

import java.util.HashSet;
import java.util.Set;

public class FortunateNumbers {

	public static int getFortunate(int[] a, int[] b, int[] c){
		Set<Integer> fortunate = new HashSet<Integer>();
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				for (int k = 0; k < c.length; k++) {
					int candidate = a[i] + b[j] + c[k];
					boolean skip = false;
					for(char n : String.valueOf(candidate).toCharArray()){
						if(n != '5' && n != '8')
							skip = true;
					}
					if(!skip)
						fortunate.add(candidate);
				}
			}
		}
		return fortunate.size();
	}
	
	public static void main(String[] args) {
		
		int[] a = { 1, 10, 100 };
		int[] b = { 3, 53 };
		int[] c = { 4, 54 };
		
		System.out.println(getFortunate(a,b,c));
	}
}
